// ChatServerDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ChatServer.h"
#include "ChatServerDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CChatServerDlg dialog




CChatServerDlg::CChatServerDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CChatServerDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CChatServerDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDITMSG, m_msg);
	DDX_Text(pDX, IDC_EDITMSG, m_Strmsg);
	DDX_Control(pDX, IDC_LISTUSER, m_lstUser);

	DDX_Control(pDX, IDC_LISTONLINEUSER, m_listname);
	DDX_Control(pDX, IDC_COMBOUSERTYPE, m_cmbGroup);
}

BEGIN_MESSAGE_MAP(CChatServerDlg, CDialog)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_MESSAGE (WM_SOCKET, SockMsg)
	ON_BN_CLICKED(IDC_BUTTONOPENCONNECTION, &CChatServerDlg::OnBnClickedButtonopenconnection)
	ON_BN_CLICKED(IDC_BUTTONCLOSECONNECTION, &CChatServerDlg::OnBnClickedButtoncloseconnection)
	ON_BN_CLICKED(IDC_BUTTONQUIT, &CChatServerDlg::OnBnClickedButtonquit)
	ON_BN_CLICKED(IDC_BUTTONUPDATEGROUP, &CChatServerDlg::OnBnClickedButtonupdategroup)
	ON_NOTIFY(NM_CLICK, IDC_LISTUSER, &CChatServerDlg::OnNMClickListuser)
END_MESSAGE_MAP()


// CChatServerDlg message handlers

BOOL CChatServerDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	InitListControl();
	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here
	WORD wVersionRequested;
	WSADATA wsaData;
	wVersionRequested=MAKEWORD(2,2);
	int err=WSAStartup(wVersionRequested,&wsaData);
	if (err!=0)
		MessageBox(_T("Can't initialize socket"));
	//Clear list client
	list_client.empty();
	isClose = false;
	
	accMgr = new AccountManager();
	accClick = NULL;
	return TRUE;  // return TRUE  unless you set the focus to a control
}


// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CChatServerDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CChatServerDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


void CChatServerDlg::OnBnClickedButtonopenconnection()
{
	// TODO: Add your control notification handler code here
	UpdateData(FALSE);
	sockServer = socket(AF_INET, SOCK_STREAM, 0);
	serverAdd.sin_family=AF_INET;
	serverAdd.sin_port = htons(PORT);    
	serverAdd.sin_addr.s_addr = htonl(INADDR_ANY);
	bind(sockServer, (SOCKADDR *)&serverAdd, sizeof(serverAdd));
	listen(sockServer,5);
	int err=WSAAsyncSelect(sockServer,m_hWnd,WM_SOCKET,
		FD_READ|FD_ACCEPT|FD_CLOSE);
	if (err)
	{
		err = WSAGetLastError();
		MessageBox(_T("Cant call WSAAsyncSelect"));	
	}
	GetDlgItem(IDC_BUTTONOPENCONNECTION)->EnableWindow(FALSE);
	return;
}

void CChatServerDlg::OnBnClickedButtoncloseconnection()
{
	// TODO: Add your control notification handler code here

}

LRESULT CChatServerDlg::SockMsg(WPARAM wParam, LPARAM lParam)
{
	if (WSAGETSELECTERROR(lParam))
    {
		 // Display the error and close the socket
		closesocket(wParam);
    }
	list<Client>::iterator i;

	switch(WSAGETSELECTEVENT(lParam))
    {
		case FD_ACCEPT:
			client.socket = accept(wParam,NULL,NULL);
			client.msgType = 0;
			client.name = _T("");
			list_client.push_back(client);	
			break;
		case FD_READ:
			//Ben client gui thong diep
			for( i = list_client.begin(); i != list_client.end(); i++)
				if( i->socket == wParam)					
					break;
				
			if (!i->msgType)
			{
				recv(i->socket,(char*)&(i->buffLength),sizeof(int),0);
				i->msgType = 1;
			}
			else
			{
				UpdateData();
				char* buffer=new char[i->buffLength+1];
				CString msg;
				char Type;

				recv(i->socket,buffer,i->buffLength,0);
				buffer[i->buffLength]='\0';
				i->msgType = 0;
				Type = buffer[0];
				msg = buffer + 1;
				switch (buffer[0])
				{
					case '0':
						UpdateData();
						break;
					case '1':
						HandleNameClient(msg,i);
						break;
					case '3'://Nhan dc message chat
						UpdateData();
						if(i->name == _T(""))//Kiem tra da dang nhap chua
							break;
						HandleChat(msg,i);
						UpdateData(false);
						m_msg.SetSel(m_msg.GetWindowTextLengthW(),m_msg.GetWindowTextLengthW());						
						
						break;
					case '6':
						HandleClientLogOut(i);
						break;
					case 'A':
						ManageAccount(msg,i);
						break;
						
				}
				delete buffer;
			}
			break;

		case FD_CLOSE:					
			for( i = list_client.begin(); i != list_client.end(); i++)
				if( i->socket == wParam)
				{
					if(!isClose)
					{
						CString annstr = _T("");
						if(i->name != _T(""))
						{
							//
							UpdateData();
							m_Strmsg = m_Strmsg + _T("Thong bao: ") + i->name + _T(" da thoat khoi room.\r\n");
							UpdateData(false);
							//
							CString nameClient = i->name;
							i->name = _T("");
							annstr = _T('2') +  nameClient;
							annstr = annstr + _T(" da thoat khoi room");
							for(int k = 0;k < m_listname.GetCount();k++)
							{
								CString nameItem;
								m_listname.GetText(k,nameItem);
								if(nameItem == nameClient)
								{								
									m_listname.DeleteString(k);
									nameClient = '5' + nameClient;
									BroadClients(nameClient,i);									
									break;
								}
							}
						}
						list_client.erase(i);
						if(annstr != _T(""))
						{						
							BroadClients(annstr,list_client.end());
						}
						break;
					}
					else
					{
						list_client.erase(i);
						break;
					}
				}			
			closesocket(wParam);
			break;			
	}
	return 0;
}
void CChatServerDlg::BroadClients(CString annstr,list<Client>::iterator i)
{	
	list<Client>::iterator j;
	for( j = list_client.begin() ; j != list_client.end(); j++)
	{
		if(i == j)
			continue;
		SendMessageToClient(annstr,j->socket);
	}
}
void CChatServerDlg::BroadClientsNotWithoutName(CString annstr,list<Client>::iterator i)
{	
	list<Client>::iterator j;	
	for( j = list_client.begin() ; j != list_client.end(); j++)
	{
		if((i == j )|| (j->name == _T("")))
			continue;
		SendMessageToClient(annstr,j->socket);
	}
}

void CChatServerDlg::HandleNameClient(CString msg,list<Client>::iterator i)
{
	CString name = _T("");
	name = msg;
	if(name == _T(""))
	{
		char* bufferError = "0Ten dang nhap khong hop le\0";
		int len = 27;
		send(i->socket,(char*)&len,sizeof(int),0);
		send(i->socket,bufferError,26,0);
		list_client.erase(i);
		name = _T("");
		return;
	}
	for(list<Client>::iterator j = list_client.begin() ; j != list_client.end(); j++)
		if( j ->name == name)
		{
			char* bufferError = "0Ten dang nhap da ton tai\0";
			int len = 26;
			send(i->socket,(char*)&len,sizeof(int),0);
			send(i->socket,bufferError,26,0);
			list_client.erase(i);
			name = _T("");
			break;
		}
	if(name !=  _T(""))
	{
		//
		UpdateData();
		m_Strmsg = m_Strmsg + _T("Thong bao: ") + name + _T(" da dang nhap.\r\n");
		UpdateData(false);
		//
		i->name = name;
		m_listname.AddString(name);
		CString mess = _T('2') + name + _T(" da dang nhap.");
		BroadClients(mess,list_client.end());
		mess = '4' + name;
		BroadClients(mess,list_client.end());

	}
}
void CChatServerDlg::OnClose()
{
	// TODO: Add your message handler code here and/or call default
	for(list<Client>::iterator j = list_client.begin() ; j != list_client.end(); j++)
	{
		shutdown(j->socket,SD_BOTH);
	}
	closesocket(sockServer);
	isClose = true;
	CDialog::OnClose();
}

void CChatServerDlg::SendMember(CString name, SOCKET sclient,char type)
{
	CString sendName = type + name;
	int Len = sendName.GetLength();
	char* sendBuff=new char[Len+1];
	strcpy(sendBuff,(char*)LPCTSTR(sendName));
	send(sclient,(char*)&Len,sizeof(Len),0);
	send(sclient,(char*)sendBuff,Len,0);
	delete sendBuff;

}

void CChatServerDlg::OnBnClickedButtonquit()
{
	// TODO: Add your control notification handler code here
	OnClose();
	DestroyWindow();
	/*
	if(list_client.empty())
	{
		DestroyWindow();
		return;
	}

	CString mess = _T("");
	mess += '0';
	mess += "Server tat";
	isClose = true;
	BroadClients(mess,list_client.end());	
	closesocket(sockServer);
	*/
}

/*Phan cua Huy */

void CChatServerDlg::HandleClientLogOut(list<Client>::iterator i)
{
	CString annstr = _T("");
	if(i->name != _T(""))
	{
		//
		UpdateData();
		m_Strmsg = m_Strmsg + _T("Thong bao: ") + i->name + _T(" da thoat khoi room.\r\n");
		UpdateData(false);
		//
		CString nameClient = i->name;
		i->name = _T("");
		annstr = _T('2') +  nameClient;
		annstr = annstr + _T(" da thoat khoi room");
		BroadClients(nameClient,i);	
		for(int k = 0;k < m_listname.GetCount();k++)
		{
			CString nameItem;
			m_listname.GetText(k,nameItem);
			if(nameItem == nameClient)
			{								
				m_listname.DeleteString(k);
				UpdateUserStatus(nameClient,false);
				nameClient = '5' + nameClient;
				BroadClients(nameClient,i);									
				break;
			}
		}
	}	
}

void CChatServerDlg::InitListControl()
{
	ListView_SetExtendedListViewStyle(m_lstUser, LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);	
	m_lstUser.InsertColumn(0, _T("STT"), LVCFMT_LEFT, 35);
	m_lstUser.InsertColumn(1, _T("Username"), LVCFMT_LEFT, 110);
	m_lstUser.InsertColumn(2, _T("Group"), LVCFMT_LEFT, 50);
	m_lstUser.InsertColumn(3, _T("Status"), LVCFMT_LEFT, 60);

	m_cmbGroup.AddString(_T("Normal"));
	m_cmbGroup.AddString(_T("Vip"));
	LoadAccountList();

}

void CChatServerDlg::LoadAccountList()
{
	m_lstUser.DeleteAllItems();
	std::vector<Account*> lstAccount = this->accMgr->GetAccountList();
	for(int i = 0;i < lstAccount.size();i++)
	{
		Account* acc = (Account*)lstAccount[i];
		m_lstUser.InsertItem(i, NULL);
		m_lstUser.SetItemText(i, 0, ToCString(i + 1));
		m_lstUser.SetItemText(i, 1, acc->m_StrUserName);
		m_lstUser.SetItemText(i, 2, acc->m_StrGroup);
		m_lstUser.SetItemText(i, 3, _T("Offline"));
	}
	int count = m_listname.GetCount();
	CString name;
	for(int i = 0; i < count; i ++)
	{
		m_listname.GetText(i,name);
		UpdateUserStatus(name,true);
	}


}
CString CChatServerDlg::ToCString(int iNum)
{
	char buffer[100];
	char* str = itoa(iNum, buffer, 10);
	return CString(str);
}

void CChatServerDlg::OnBnClickedButtonupdategroup()
{
	// TODO: Add your control notification handler code here
	if(accClick && m_cmbGroup.GetCurSel() == 0)
	{
		accMgr->ChangeGroup(accClick->m_StrUserName,_T("Normal"));

	}
	else if (accClick && m_cmbGroup.GetCurSel() == 1)
	{
		accMgr->ChangeGroup(accClick->m_StrUserName,_T("Vip"));
	}
	LoadAccountList();
}

void CChatServerDlg::OnNMClickListuser(NMHDR *pNMHDR, LRESULT *pResult)
{
	NM_LISTVIEW* pNM = (NM_LISTVIEW*)pNMHDR;
	int nCount = m_lstUser.GetItemCount();
    LVHITTESTINFO ht;
    ht.pt = pNM->ptAction;
    m_lstUser.SubItemHitTest(&ht);

	if(ht.iItem >= 0 && ht.iItem < nCount)
	{
		accClick = new Account();
		accClick->m_StrUserName = m_lstUser.GetItemText(ht.iItem, 1);
		accClick->m_StrGroup = m_lstUser.GetItemText(ht.iItem,2);
		if(accClick)
		{
			//Set cho combobox
			if(accClick->m_StrGroup == _T("Vip"))
				m_cmbGroup.SetCurSel(1);
			else
				m_cmbGroup.SetCurSel(0);

		}
	}
	else
	{
		accClick = NULL;
	}
}

void CChatServerDlg::SendMessageToClient(CString msg,SOCKET sClient)
{
	int Len = msg.GetLength();
	char *sendBuff = new char[Len+1];
	wcstombs(sendBuff, msg, Len+1);
	//Send kich thuoc truoc
	send(sClient,(char*)&Len,sizeof(Len),0);
	send(sClient,(char*)sendBuff,Len,0);

}

void CChatServerDlg::ManageAccount(CString msg,list<Client>::iterator i)
{
	Account* acc;
	char Type = msg[0];
	msg.Delete(0,1);
	int error;
	list<Client>::iterator j;
	switch(Type)
	{
	case '0'://Tao tai khoan moi	
		error = CreateAccount(msg);
		if(error == 0)
		{			
			SendMessageToClient(_T("A1Tao user thanh cong."),i->socket);//Thong bao tao thanh cong thanh cong
			LoadAccountList();
		}
		else if( error == NERR_UserExists)
		{
			SendMessageToClient(_T("A2User nay da ton tai."),i->socket);//Thong bao tao user that bai
		}
		else
		{
			SendMessageToClient(_T("A2Tao user that bai."),i->socket);//Thong bao tao user that bai
		}

		break;
	case '3'://Dang nhap
		if(LogIn(msg))
		{
			//msg = username
			CString username;
			int len = _ttoi(msg.Mid(0,2));
			msg.Delete(0,2);
			username = msg.Mid(0,len);
			HandleOnlineNameClient(username,i);
			
		}
		else
			SendMessageToClient(_T("A5Dang nhap that bai."),i->socket);//Gui ve thong bao thanh cong + loai group
		break;
		
	case '9': //Edit user
		//Kiem tra user
		if(i->name == _T(""))//Kiem tra dang nhap chua
			SendMessageToClient(_T("ABPhai dang nhap moi duoc quyen edit"),i->socket);
		else if(i->groupType == _T("0"))//Kiem tra quyen han
			SendMessageToClient(_T("ABBan khong phai la tai khoan Vip"),i->socket);		
		else
		{
			acc = new Account();			
			int len = _ttoi(msg.Mid(0,2));
			msg.Delete(0,2);
			acc->m_StrUserName = msg.Mid(0,len);
			msg.Delete(0,len);

			len = _ttoi(msg.Mid(0,2));
			msg.Delete(0,2);
			acc->m_StrDescription = msg.Mid(0,len);
			
			if(accMgr->getGroupName(acc->m_StrUserName) == _T("Vip"))
			{
				SendMessageToClient(_T("ABDay la tai khoan Vip, khong duoc quyen edit"),i->socket);
			}
			else
			{
				error = accMgr->ChangeAccountInfo(acc); //Tra ve ma loi
				if(error == 0)
					SendMessageToClient(_T("AACap nhat tai khoan thanh cong"),i->socket);
				else if(error == NERR_UserNotFound)
					SendMessageToClient(_T("ABUser nay khong ton tai"),i->socket);
				else
					SendMessageToClient(_T("ABEdit that bai"),i->socket);
			}
			
		}
		//
		break;
	case 'C'://Xoa user
		if(i->name == _T(""))//Kiem tra dang nhap chua
			SendMessageToClient(_T("AEPhai dang nhap moi duoc quyen xoa"),i->socket);
		else if(i->groupType == _T("0"))//Kiem tra quyen han
			SendMessageToClient(_T("AEBan khong phai la tai khoan Vip"),i->socket);		
		else
		{
			//Check online
			for(j = list_client.begin() ; j !=  list_client.end() ;j++)
				if(j->name != _T("") && j->name == msg)
				{
					SendMessageToClient(_T("AEUser nay dang online"),i->socket);
					return;
				}
			//
			acc = new Account();
			acc->m_StrUserName = msg;

			if(accMgr->getGroupName(acc->m_StrUserName) == _T("Vip"))
			{
				SendMessageToClient(_T("AEDay la tai khoan Vip, khong duoc quyen xoa"),i->socket);
			}
			else
			{

				error = accMgr->DeleteAccount(acc);
				if(error == 0)
				{
					SendMessageToClient(_T("ADXoa tai khoan thanh cong"),i->socket);
					LoadAccountList();
				}
				else if(error == NERR_UserNotFound)
					SendMessageToClient(_T("AEUser nay khong ton tai"),i->socket);
				else
					SendMessageToClient(_T("AEXoa that bai"),i->socket);
			}
		}
		break;

	case '7'://Gui danh sach account Normal toi cho user Vip
		std::vector<Account*> lstAccount = this->accMgr->GetGroupAccountList(_T("Normal"));
		int size = lstAccount.size();
		for(int j = 0; j < size; j++)
		{
			CString username = lstAccount[j]->m_StrUserName;
			CString description = lstAccount[j]->m_StrDescription;
			CString message = _T("A8");
			if(username.GetLength() < 10)
				message += _T("0");
			message += ToCString(username.GetLength()) + username;			
			if(description.GetLength() < 10)
				message += _T("0");
			message += ToCString(description.GetLength()) + description;
			SendMessageToClient(message,i->socket);
		}
		break;
	


		
	}
}

int CChatServerDlg::CreateAccount(CString msg)
{
	Account* acc = new Account(); 
	//Lay username
	int len = _ttoi(msg.Mid(0,2));
	msg.Delete(0,2);
	acc->m_StrUserName = msg.Mid(0,len);
	msg.Delete(0,len);
	
	//Lay password
	len = _ttoi(msg.Mid(0,2));
	msg.Delete(0,2);
	acc->m_StrPassword = msg.Mid(0,len);
	msg.Delete(0,len);

	//Lay Description
	len = _ttoi(msg.Mid(0,2));
	msg.Delete(0,2);
	acc->m_StrDescription = msg.Mid(0,len);
	msg.Delete(0,len);

	return accMgr->CreateAccount(acc,_T("Normal"));

}

bool CChatServerDlg::LogIn(CString msg)
{
	CString username,password;
	int len = _ttoi(msg.Mid(0,2));
	msg.Delete(0,2);
	username = msg.Mid(0,len);
	msg.Delete(0,len);
	
	//Lay password
	len = _ttoi(msg.Mid(0,2));
	msg.Delete(0,2);
	password = msg.Mid(0,len);
	msg.Delete(0,len);
	PHANDLE token = new HANDLE();
	msg = username;
	return LogonUser(username,NULL,password,LOGON32_LOGON_INTERACTIVE,LOGON32_PROVIDER_DEFAULT,token);
	 
	
}
void CChatServerDlg::HandleOnlineNameClient(CString username,list<Client>::iterator i)
{
	
	CString name = _T("");
	name = username;
	//Kiem tra tai khoan nay da Online chua
	for(list<Client>::iterator j = list_client.begin() ; j != list_client.end(); j++)
		if( j ->name == name)
		{
			SendMessageToClient(_T("A5Tai khoan nay dang online"),i->socket);//Thong bao dang nhap that bai
			return;
		};

	
	CString groupName = accMgr->getGroupName(username);
	UpdateData();
	if(groupName ==_T("Vip"))
	{
		SendMessageToClient(_T("A41"),i->socket);
		i->groupType = _T("1");		
	}
	else
	{
		SendMessageToClient(_T("A40"),i->socket);
		i->groupType = _T("0");
	}

	m_Strmsg = m_Strmsg + _T("Thong bao: ") + name + _T(" da dang nhap.\r\n");
	UpdateData(false);
	//
	i->name = name;
	m_listname.AddString(name);
	//Cap nhat vao danh sach tai khoan trang thai Online
	UpdateUserStatus(name,true);
	//
	CString mess = _T('2') + name + _T(" da dang nhap.");
	BroadClientsNotWithoutName(mess,list_client.end());//Thong bao toi cac client da dang nhap rang <name> da dang nhap
	mess = '4' +i->groupType+ name;
	BroadClientsNotWithoutName(mess,i);//Yeu cau cac client da dang nhap add <name> vao danh sach tai khoan dang online
	
	//Gui danh sach client dang online cho client vua dang nhap
	for(list<Client>::iterator j = list_client.begin() ; j != list_client.end(); j++)
		if( j ->name != _T(""))
		{
			mess = '4'+j->groupType+j->name;
			SendMessageToClient(mess,i->socket);
		};
	//

}

void CChatServerDlg::UpdateUserStatus(CString name,bool flag)
{
	int count = m_lstUser.GetItemCount();
	CString status;
	if(flag)
		status = _T("Online");
	else
		status = _T("Offline");
	for(int i = 0; i < count ; i++)
	{
		if(m_lstUser.GetItemText(i,1) == name)
		{
			m_lstUser.SetItemText(i,3,status);
		}
	}
	UpdateData(false);
}


void CChatServerDlg::HandleChat(CString msg,list<Client>::iterator i)
{
	UpdateData();
	char Type = msg[0];
	CString username;
	int len;
	list<Client>::iterator j;
	msg.Delete(0,1);
	UpdateData();
	switch(Type)
	{
	case '0'://Chat ALL
		
		if(i->name == _T(""))//Kiem tra da dang nhap chua
			break;
		m_Strmsg = m_Strmsg + i->name + _T("[ALL]: ") + msg + _T("\r\n");
		UpdateData(false);
		m_msg.SetSel(m_msg.GetWindowTextLengthW(),m_msg.GetWindowTextLengthW());
		msg = '3' + i->name + _T("[ALL]: ") + msg;
		BroadClients(msg,i);
		break;
	case '1'://Chat voi 1 user cu the
		
		len = _ttoi(msg.Mid(0,2));
		msg.Delete(0,2);
		username = msg.Mid(0,len);
		msg.Delete(0,len);

		//Tim ra socket tuong ung
		for(j = list_client.begin() ; j != list_client.end(); j++)
			if(j->name != _T("") && j ->name == username)			
				break;

		//Neu co user nay
		if(j != list_client.end())
		{
			CString annstr = '3' + j->name + ':' + msg;
			SendMessageToClient(annstr,j->socket);
			m_Strmsg = m_Strmsg + i->name + _T(" : ") + j->name + _T(" : ") + msg + _T("\r\n");
		}
		else
			SendMessageToClient(_T("2Tai khoan ")+ username +_T(" khong ton tai trong list online."),i->socket);
		break;
	}
}
/*Het phan cua Huy*/